package com.atguigu.gulicollege.service_oss.controller;

import com.atguigu.gulicollege.commonutils.R;
import com.atguigu.gulicollege.service_oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/eduoss")
//@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    //上传头像的方法
    // 上传头像到oss  提交到服务端  服务端提交到OOS     --不建议
    @PostMapping("/fileoss")
    public R uploadOssFile(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }


    // 向后台要验签  前台直接提交到OOS  建议
    @GetMapping("/policy")
    public R uplodepolicy() {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        Map<String, String> url = ossService.uplodepolicy();
        return R.ok().data("url",url);
    }

}
